package com.zj.core.ui

import android.content.Context
import android.graphics.Color
import android.view.Gravity
import android.view.View
import android.widget.LinearLayout
import android.widget.SeekBar
import android.widget.TextView
import com.zj.core.R
import org.jetbrains.anko.*

class DialogTextSizeUi(context: Context,listener: View.OnClickListener,seekListener: SeekBar.OnSeekBarChangeListener) {
    private var mSeekListener: SeekBar.OnSeekBarChangeListener=seekListener
    private var mLstaner: View.OnClickListener=listener
    private var mContext: Context = context

    var seek_bar_view:SeekBar ?=null
    var change_text_size:TextView ?=null
    var common_dialog_cancel_tv:TextView ?=null
    var common_dialog_confirm_tv:TextView ?=null
    var view_root_dialog:LinearLayout?=null

    init {
        view_root_dialog=mContext.linearLayout {
            orientation = LinearLayout.VERTICAL
            background = context.resources.getDrawable(R.drawable.popup_dialog_bg)

            textView {
                text = "修改字号"
                gravity = Gravity.CENTER
                textSize = dip(12).toFloat()
                textColor = Color.parseColor("#555555")
            }.lparams(width = matchParent, height = dip(40)) {
                topMargin = dip(10)
                bottomMargin=dip(10)
            }

            view {
                backgroundColor = Color.parseColor("#F5F5F5")
            }.lparams(width = matchParent, height = dip(1))

            relativeLayout {
                seek_bar_view=seekBar {
                    id = R.id.seek_bar_view
                    max = 40
                    setOnSeekBarChangeListener(mSeekListener)
                    progressDrawable=mContext.resources.getDrawable(R.drawable.po_seekbar)
                    thumb=mContext.resources.getDrawable(R.drawable.detail_icon_schedule_ball)

                    try{
                        val superclass=javaClass.superclass.superclass
                        val mMaxHeight=superclass.getDeclaredField("mMaxHeight")
                        mMaxHeight.isAccessible=true
                        mMaxHeight.set(this,8)
                        val mMinHeight =superclass.getDeclaredField("mMinHeight")
                        mMinHeight .isAccessible=true
                        mMinHeight .set(this,8)
                    }catch (e:Exception){
                        e.printStackTrace()
                    }
                }.lparams(width = matchParent, height = wrapContent){
                    leftMargin=dip(8)
                    rightMargin=dip(8)
                }

                change_text_size=textView {
                    textColor = context.resources.getColor(R.color.colorsDarkGray)
                    id = R.id.change_text_size
                    gravity = Gravity.CENTER
                }.lparams(width = matchParent, height = matchParent) {
                    margin = dip(20)
                    below(R.id.seek_bar_view)
                }
            }.lparams(width = matchParent, height = 0) {
                weight = 1F
                topMargin = dip(25)
            }

            view {
                backgroundColor = Color.parseColor("#F5F5F5")
            }.lparams(width = matchParent, height = dip(1))

            linearLayout {
                orientation = LinearLayout.HORIZONTAL

                common_dialog_cancel_tv=textView {
                    id = R.id.common_dialog_cancel_tv
                    isClickable = true
                    text = "取消"
                    setOnClickListener(mLstaner)
                    textColor = Color.parseColor("#0679FE")
                    textSize = dip(10).toFloat()
                    gravity = Gravity.CENTER
                }.lparams(width = 0, height = matchParent){
                    weight = 1F
                }

                view {
                    backgroundColor = Color.parseColor("#F5F5F5")
                }.lparams(width = dip(1), height = matchParent)

                common_dialog_confirm_tv=textView {
                    id = R.id.common_dialog_confirm_tv
                    isClickable = true
                    setOnClickListener(mLstaner)
                    gravity = Gravity.CENTER
                    text = "确定"
                    textSize = dip(10).toFloat()
                    textColor = Color.parseColor("#0679FE")
                }.lparams(width = 0, height = matchParent) {
                    weight = 1F
                }
            }.lparams(width = matchParent, height = dip(50))
        }
    }
}
